#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
#include <time.h>
#include <sys/time.h>

#include "../engine/engine.h"
#include "../utility/ugx_palloc.h"
#include "../net/request.h"

#include <glog/logging.h>

#ifdef __cplusplus
extern "C" {
#endif

	bool init(int argc, char* argv[])
	{
		//parser argv and init
		//TODO
		return true;
	}

	void uninit()
	{
		//uninit
		//TODO
	}

	uint8_t* process_sync(_pool_t* pool, const void* data, size_t data_len,struct request_tag* request, size_t* output_len)
	{
		unsigned char* output = (unsigned char*)_palloc(pool, data_len);
		*output_len =data_len;
		memcpy(output, data, data_len);
		printf("sync#@%s\n", (const char*)data);
		return output;
	}

	void process_async(_pool_t* pool, void* buffer, size_t buffer_size, finish_callback callback, void* user_data)
	{
		//request_t* request = (request_t*)user_data;
		char* response = (char*)_palloc(pool, buffer_size);
		memcpy(response, buffer, buffer_size);
		printf("async#@%s\n", (const char*)buffer);
		callback(response, buffer_size, user_data);
	}

#ifdef __cplusplus
}
#endif
